package com.bj58.migrate.bll;

import java.util.HashMap;
import java.util.Map;

import com.bj58.migrate.ScfProxy;
import com.bj58.sfft.cmc.entity.Category;
import com.bj58.sfft.cmc.entity.DispCategoryExt;
import com.bj58.sfft.cmc.entity.Local;

/**
 * Created by lvzheng on 2014/8/8.
 */
public class CMCSBll{

    private static Map< Integer, DispCategoryExt > cateExtCache = new HashMap< Integer, DispCategoryExt >();
    private static Map< Integer, Category > cateCache = new HashMap< Integer, Category >();
    private static Map< Integer, Local > localCache = new HashMap< Integer, Local >();

    public static Category GetCatetory( int cateid ){

        Category ext = cateCache.get( cateid );

        if( ext != null ){
            return ext;
        }

        try{
            Category dext = ScfProxy.cmc_Category().GetCategoryByID( cateid );
            if( dext != null ){
                cateCache.put( cateid, dext );
            }
            return dext;
        }
        catch( Exception e ){
            return null;
        }
    }

    public static DispCategoryExt GetDefaultDispCateByID( int cateid ){

        DispCategoryExt ext = cateExtCache.get( cateid );

        if( ext != null ){
            return ext;
        }

        try{
            DispCategoryExt dext = ScfProxy.cmc_DispCategory().GetDefaultDispCateByID( cateid );
            if( dext != null ){
                cateExtCache.put( cateid, dext );
            }

            return dext;
        }
        catch( Exception ex ){
            return null;
        }
    }

    public static Local GetDispLocal( int local ){

        Local ext = localCache.get( local );

        if( ext != null ){
            return ext;
        }

        try{
            Local nDispLocal = ScfProxy.cmc_Local().GetLocalByID( local );
            if( nDispLocal != null ){
                localCache.put( local, nDispLocal );
            }

            return nDispLocal;
        }
        catch( Exception e ){
            return null;
        }
    }
}
